<?php
/**
 * 模拟一个多线程请求url
 */

$urls = [
    '01_http://www.baidu.com',
    '01_http://www.sina.com',
    '01_http://www.so.com'
];

$works = [];

echo "程序开始运行时间:" . date('Y-m-d H:i:s') . PHP_EOL;
foreach ($urls as $url) {
    $process = new swoole_process(function($childProcess) use($url) {
        $context = curl($url);
        $childProcess->write($context);
    }, true);
    $pid = $process->start();
    $works[$pid] = $process;
}
foreach ($works as $work) {
    echo $work->read() . PHP_EOL;
}

echo "程序结束运行时间:" . date('Y-m-d H:i:s') . PHP_EOL;

function curl($url) {
    sleep(1);  // 模拟请求的耗时
    return $url . '=============>success' . PHP_EOL;
}
